package Day2025_03_05;

public class LeetCode844 {
    public boolean backspaceCompare(String s, String t) {
        return changeStr(s).equals(changeStr(t));
    }
    private String changeStr (String s) {
        StringBuffer ret = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != '#') ret.append(s.charAt(i));
            else {
                if (ret.length() > 0) ret.deleteCharAt(ret.length() - 1);
            }
        }
        return ret.toString();
    }
}
